import Taro, { Component } from '@tarojs/taro'
import Index from './pages/index/temp/index'
import { Provider } from '@tarojs/redux'
import {IntlProvider, addLocaleData} from 'react-intl'
import configStore from './store'
import en from 'react-intl/locale-data/en'
import zh from 'react-intl/locale-data/zh'
import '@tarojs/async-await'
import './icon.scss'
import './app.scss'
//import i18nData from './i18n/data'
//import i18nData from './i18n/data'
addLocaleData([...en, ...zh])

const store = configStore()
//const messages = i18nData.en
class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      lang: 'en'
    }
  }

  config = {
    pages: [
      'pages/index/index',
      'pages/index/challenge/index',
      'pages/index/me/index',
      'pages/index/search/index',
      'pages/index/challengeDetail/index',
      'pages/index/group/index',
      'pages/index/home/index',
      //'pages/index/list/index',
      'pages/index/result/index'
    ]
  }

  componentDidMount () {
    //getUserInfo --> 获取language
    //修改state
    wx.cloud.callFunction({
      // 要调用的云函数名称
      name: 'login',
      success: res => {
        //console.log(res.result)
        Taro.setStorageSync('openid', res.result.openid.openId)
      },
      fail: err => {
        //console.log(err)
      }
    })
  }

  componentWillMount () {
    if (!wx.cloud) {
      console.log("please use weixin 2.3+")
    } else {
      wx.cloud.init({
        traceUser: true
      });
    }
  }

  componentDidShow () {}

  componentDidHide () {}

  componentCatchError () {}

  componentDidCatchError () {}

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render () {
    return (
      <Provider store={store}>
        <IntlProvider locale={this.state.lang} messages={messages}>
          <Index />
        </IntlProvider>
      </Provider>
    )
  }
}

Taro.render(<App />, document.getElementById('app'))
